public class FoxPlayingGame {
	public double theMax(int nA, int nB, int paramA, int paramB) {
		double[][] minAnswer = new double[nA + 1][nB + 1];
		double[][] maxAnswer = new double[nA + 1][nB + 1];
		for (int i = 1; i <= nB; i++) {
			minAnswer[0][i] = Math.min(minAnswer[0][i - 1] * paramB / 1000, maxAnswer[0][i - 1] * paramB / 1000);
			maxAnswer[0][i] = Math.max(minAnswer[0][i - 1] * paramB / 1000, maxAnswer[0][i - 1] * paramB / 1000);
		}
		for (int i = 1; i <= nA; i++) {
			minAnswer[i][0] = Math.min(minAnswer[i - 1][0] + paramA / 1000., maxAnswer[i - 1][0] + paramA / 1000.);
			maxAnswer[i][0] = Math.max(minAnswer[i - 1][0] + paramA / 1000., maxAnswer[i - 1][0] + paramA / 1000.);
			for (int j = 1; j <= nB; j++) {
				maxAnswer[i][j] = Math.max(Math.max(minAnswer[i][j - 1] * paramB / 1000, minAnswer[i - 1][j] + paramA / 1000.),
						Math.max(maxAnswer[i][j - 1] * paramB / 1000, maxAnswer[i - 1][j] + paramA / 1000.));
				minAnswer[i][j] = Math.min(Math.min(minAnswer[i][j - 1] * paramB / 1000, minAnswer[i - 1][j] + paramA / 1000.),
						Math.min(maxAnswer[i][j - 1] * paramB / 1000, maxAnswer[i - 1][j] + paramA / 1000.));
			}
		}
		return maxAnswer[nA][nB];
	}

// BEGIN CUT HERE
   public static void main(String[] args) {
		if ( args.length == 0 ) {
			FoxPlayingGameHarness.run_test(-1);
		} else {
			for ( int i=0; i<args.length; ++i )
				FoxPlayingGameHarness.run_test(Integer.valueOf(args[i]));
		}
	}
// END CUT HERE
}

// BEGIN CUT HERE
class FoxPlayingGameHarness {
	public static void run_test( int casenum ) {
		if ( casenum != -1 ) {
			if ( runTestCase( casenum ) == -1 )
				System.err.println("Illegal input! Test case " + casenum + " does not exist.");
			return;
		}
		
		int correct = 0, total = 0;
		for ( int i=0;; ++i ) {
			int x = runTestCase(i);
			if ( x == -1 ) {
				if ( i >= 100 ) break;
				continue;
			}
			correct += x;
			++total;
		}
		
		if ( total == 0 ) {
			System.err.println("No test cases run.");
		} else if ( correct < total ) {
			System.err.println("Some cases FAILED (passed " + correct + " of " + total + ").");
		} else {
			System.err.println("All " + total + " tests passed!");
		}
	}
	
	static final double MAX_DOUBLE_ERROR = 1E-9;
	static boolean compareOutput(double expected, double result){ if(Double.isNaN(expected)){ return Double.isNaN(result); }else if(Double.isInfinite(expected)){ if(expected > 0){ return result > 0 && Double.isInfinite(result); }else{ return result < 0 && Double.isInfinite(result); } }else if(Double.isNaN(result) || Double.isInfinite(result)){ return false; }else if(Math.abs(result - expected) < MAX_DOUBLE_ERROR){ return true; }else{ double min = Math.min(expected * (1.0 - MAX_DOUBLE_ERROR), expected * (1.0 + MAX_DOUBLE_ERROR)); double max = Math.max(expected * (1.0 - MAX_DOUBLE_ERROR), expected * (1.0 + MAX_DOUBLE_ERROR)); return result > min && result < max; } }
	static double relativeError(double expected, double result) { if ( Double.isNaN( expected ) || Double.isInfinite( expected ) || Double.isNaN( result ) || Double.isInfinite( result ) || expected == 0 ) return 0; return Math.abs( result-expected ) / Math.abs( expected ); }
	
	static String formatResult(double res) {
		return String.format("%.10g", res);
	}
	
	static int verifyCase( int casenum, double expected, double received ) { 
		System.err.print("Example " + casenum + "... ");
		if ( compareOutput( expected, received ) ) {
			System.err.print("PASSED");
			double rerr = relativeError( expected, received );
			if ( rerr > 0 ) System.err.printf(" (relative error %g)", rerr);
			System.err.println();
			return 1;
		} else {
			System.err.println("FAILED");
			System.err.println("    Expected: " + formatResult(expected)); 
			System.err.println("    Received: " + formatResult(received)); 
			return 0;
		}
	}

	static int runTestCase( int casenum ) {
		switch( casenum ) {
		case 0: {
			int nA                    = 5;
			int nB                    = 4;
			int paramA                = 3000;
			int paramB                = 2000;
			double expected__         = 240.0;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}
		case 1: {
			int nA                    = 3;
			int nB                    = 3;
			int paramA                = 2000;
			int paramB                = 100;
			double expected__         = 6.0;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}
		case 2: {
			int nA                    = 4;
			int nB                    = 3;
			int paramA                = -2000;
			int paramB                = 2000;
			double expected__         = -8.0;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}
		case 3: {
			int nA                    = 5;
			int nB                    = 5;
			int paramA                = 2000;
			int paramB                = -2000;
			double expected__         = 160.0;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}
		case 4: {
			int nA                    = 50;
			int nB                    = 50;
			int paramA                = 10000;
			int paramB                = 2000;
			double expected__         = 5.62949953421312E17;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}
		case 5: {
			int nA                    = 41;
			int nB                    = 34;
			int paramA                = 9876;
			int paramB                = -1234;
			double expected__         = 515323.9982341775;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}

		// custom cases

/*      case 6: {
			int nA                    = ;
			int nB                    = ;
			int paramA                = ;
			int paramB                = ;
			double expected__         = ;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}*/
/*      case 7: {
			int nA                    = ;
			int nB                    = ;
			int paramA                = ;
			int paramB                = ;
			double expected__         = ;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}*/
/*      case 8: {
			int nA                    = ;
			int nB                    = ;
			int paramA                = ;
			int paramB                = ;
			double expected__         = ;

			return verifyCase( casenum, expected__, new FoxPlayingGame().theMax( nA, nB, paramA, paramB ) );
		}*/
		default:
			return -1;
		}
	}
}

// END CUT HERE
